package com.hjm.app.fragment.store;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hjm.app.R;
import com.hjm.java.entity.GoodsListVO;
import com.hjm.ui.goods.GoodsItemList;
import com.hjm.ui.goods.adapter.GoodsItemAdapter;
import com.hjm.ui.goods.entity.GoodsItem;

import java.util.ArrayList;
import java.util.List;

public class FragmentStoreAllGoods extends Fragment {

    private GoodsItemList homeGoodsItem;
    private List<GoodsItem> goodsItemList;
    private GoodsItemAdapter.Listener listener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_store_all_goods, container, false);
        homeGoodsItem = inflate.findViewById(R.id.store_goods_item);
        if (goodsItemList != null && listener != null)
            homeGoodsItem.setData(this.goodsItemList,2,listener);
        return inflate;
    }

    public void setGoodsItemList(List<GoodsListVO> goodsListVOList,GoodsItemAdapter.Listener listener) {
        this.goodsItemList = new ArrayList<>();
        for (GoodsListVO goodsListVO : goodsListVOList) {
            GoodsItem item = new GoodsItem();
            item.setId(goodsListVO.getId());
            item.setName(goodsListVO.getName());
            item.setPrice(goodsListVO.getPrice());
            item.setIconBitmap(goodsListVO.getIconBitmap());
            this.goodsItemList.add(item);
        }
        this.listener = listener;
        if (homeGoodsItem != null)
            homeGoodsItem.setData(this.goodsItemList,2,listener);
    }
}